project(vtkIGSIOCodecs)

set(${PROJECT_NAME}_EXPORT_DIRECTIVE "VTK_IGSIO_CODECS_EXPORT")

IF (NOT IGSIO_USE_3DSlicer)
  FIND_PACKAGE(vtkAddon REQUIRED)
ELSE()
  FIND_PACKAGE(Slicer REQUIRED)
ENDIF()

set(${PROJECT_NAME}_INCLUDE_DIRS
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_LIBRARY_DIR}
  ${CMAKE_CURRENT_ARCHIVE_DIR}
  ${vtkAddon_INCLUDE_DIRS}
  )

set(${PROJECT_NAME}_SRCS
  )

set(${PROJECT_NAME}_LIBS
  ${VTK_LIBRARIES}
  vtkAddon
  )

set(${PROJECT_NAME}_LIBS_PRIVATE
  )

IF(IGSIO_USE_VP9)
  FIND_PACKAGE(VP9 REQUIRED)
  LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS
    ${VP9_INCLUDE_DIR}
    )
  LIST(APPEND ${PROJECT_NAME}_SRCS
    vtkVP9VolumeCodec.cxx
    vtkVP9VolumeCodec.h
    )

  LIST(APPEND ${PROJECT_NAME}_LIBS_PRIVATE
    ${VP9_STATIC_LIBRARIES}
    )
  LINK_DIRECTORIES(${VP9_LIBRARY_DIR})
ENDIF()

IF(NOT ${PROJECT_NAME}_SRCS)
  # No codecs are enabled
  # Nothing to compile
  return()
ENDIF()

#-----------------------------------------------------------------------------
# Create the library
IF(MSVC OR ${CMAKE_GENERATOR} MATCHES "Xcode")
  ADD_LIBRARY(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS})
ELSE()
  ADD_LIBRARY(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})
ENDIF()
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
  PUBLIC ${${PROJECT_NAME}_LIBS}
  PRIVATE ${${PROJECT_NAME}_LIBS_PRIVATE}
  )
IF (NOT IGSIO_USE_3DSlicer)
  ADD_DEPENDENCIES(${PROJECT_NAME}
    vtkAddon
  )
ENDIF()

INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
  RUNTIME DESTINATION ${IGSIO_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
  LIBRARY DESTINATION ${IGSIO_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
  ARCHIVE DESTINATION ${IGSIO_INSTALL_DATA_DIR} COMPONENT Development)

FOREACH(p IN LISTS ${PROJECT_NAME}_INCLUDE_DIRS)
  TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${p}>)
ENDFOREACH()
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:${${PROJECT_NAME}_INSTALL_INCLUDE_DIR}>)

GENERATE_EXPORT_HEADER(${PROJECT_NAME})

SET_PROPERTY(GLOBAL APPEND PROPERTY IGSIO_TARGETS ${PROJECT_NAME})

SET(${PROJECT_NAME}_INCLUDE_DIRS ${${PROJECT_NAME}_INCLUDE_DIRS} CACHE INTERNAL "")
